<?php

namespace app\manage\controller;

use app\Request;
use hg\apidoc\annotation as Apidoc;
use think\response\Json;
use app\manage\services\Log as LogService;
use think\App;

/**
 * @Apidoc\Title("日志模块")
 * @Apidoc\Group("")
 */
class Log extends Base
{
    protected $service;
    protected $validate;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->service = new LogService();
    }

    /**
     * @Apidoc\Title("查询日志分页列表")
     * @Apidoc\Url("/manage/log/list")
     * @Apidoc\Header(ref="auth")
     * @Apidoc\Param(ref="pagingParam")
     * @Apidoc\Returned(ref="pagingParam")
     * @Apidoc\Param("account", type="string", desc="账号名")
     * @Apidoc\Param("type", type="int", desc="日志类型 1登录日志  2操作日志")
     * @Apidoc\Returned("data",type="array",ref="app\model\Log\getList",withoutField="")
     */
    public function getPageList(Request $request): Json
    {
        $page = $request->param("pageIndex", config('app.defaultPage'));
        $limit = $request->param("pageSize", config('app.defaultLimit'));
        $where = [];
        $user_login = $request->param("user_login", '');
        $type = $request->param("type", '');
        if ($user_login) {
            $where[] = ['user_login', 'like', '%' . $user_login . '%'];
        }
        if ($type) {
            $where[] = ['type', '=', $type];
        }
        $res = $this->service->getPageList($page, $limit, $where);
        return jsonT($res);
    }
}
